var util = require('../../libs/util.js');
var moment = require('../../libs/moment.min.js');
moment.locale('zh-cn');
//获取应用实例
var app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    StatusBar: app.globalData.StatusBar,
    CustomBar: app.globalData.CustomBar,

  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (e) {
    var that = this;
    if (e.order){
       that.setData({
         payment_delivery: e.order
       })
      that.loadData()
     }
    if (e.warehouse) {
      that.setData({
        payment_project: e.warehouse
      })
    }
  },
  loadData: function () {
    var that = this;
    wx.showLoading({
      title: '加载中',
    })
    util.getData("/atapi/finance/finance/requestDelivery", {
      'delivery': that.data.payment_delivery
    }, function (res, error) {
      console.log(res); console.log(error)
      wx.hideLoading();
      if (res.data.success) {
        that.setData(res.data.data);
      }
    });
  },
  bindInput: function (e) {
    var item = String(e.currentTarget.id), item_value = {};
    var value = e.detail.value;
    item_value[item] = value;
    this.setData(item_value);
  },
  backPage:function(){
    wx.navigateBack({
      delta: 1
    })
  },
  formSubmit: function (e) {
    var that = this;
    wx.showLoading({
      title: '提交中',
    })
    var data = {
      CO_ID: app.globalData.CO_ID,
      ADD_USER: app.globalData.user_id,
      payment_project: that.data.payment_project,
      payment_use: that.data.payment_use||'',
      amount: that.data.amount || that.data.driverPrice,
      payment_name: that.data.payment_name || that.data.driverName,
      payment_delivery: that.data.payment_delivery,
      user_id: app.globalData.user_id,
      payment_user_id: that.data.driverUserId,
      remark: that.data.remark,
      payment_phone: that.data.payment_phone,
      payment_idcard: that.data.payment_idcard,
      payment_project_name: that.data.payment_project_name || that.data.whName,
      payment_delivery_pathname: that.data.payment_delivery_pathname || that.data.path_name,
      payment_plate: that.data.payment_plate || that.data.plate
    }
    if (data.amount == '' || data.amount == undefined || Number(data.amount) < 1){
      wx.showToast({
        title: "请输入合法金额",
        image: '/images/wrong.png',
        duration: 3000
      });
      return false
    }
    util.postData("/atapi/finance/finance/paymentRequest", data, function (res, error) {
      console.log(res); console.log(error)
      if (res.data.success) {
        wx.showToast({
          title: "提交成功",
          icon: "success",
          duration: 3000,
          success: function () {
            setTimeout(function () {
              wx.navigateBack({
                delta: 1
              })
            }, 3000);
          }
        });
      } else {
        wx.showToast({
          title: "提交失败",
          image: '/images/wrong.png',
          duration: 3000
        });
      }
      wx.hideLoading();
    });
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})